package com.wawei.seeds.services;

import android.content.Context;
import android.os.Handler;

import com.wawei.seeds.model.HeroInfo;
import com.wawei.seeds.model.WalnutMainEvent;
import com.wawei.seeds.utils.RetrofitNetworkService;
import com.wawei.seeds.utils.WalnutNotifyHandler;

import java.util.ArrayList;
import java.util.List;

import retrofit.RestAdapter;

/**
 *
 * Created by t27891 on 15/6/20.
 */
public class WalnutMainServiceHandler {
    private Context context;

    public WalnutMainServiceHandler(Context context) {
        this.context = context;
    }

    public void retrieveHeroEvents(RestAdapter restAdapter, int count,
                                   final Handler handler, final Integer handlerTag) {
        List<WalnutMainEvent> items = new ArrayList<>(0);
        WalnutMainEvent item;
        switch (handlerTag.intValue()) {
            case WalnutNotifyHandler.LOAD_NEW_ACHIEVE_DATA:
                for (int i = 0; i < 2; i++) {
                    item = new WalnutMainEvent();
                    item.AD = "http://upload.jashnname.com/UploadedFiles/Core/Images/8ae6b53a-2f23-4a61-81cd-c8d6e6058c92.jpg";
                    item.title = "淘宝架构的演化过程";
                    item.action = "分享";
                    item.available = "本月可预约5次";
                    item.publisher = "苏妲己";
                    item.role = "高级架构师";
                    item.detail = "一个粗糙的产品，无法用户看上第一眼看上，那就是失败的。男人喜欢看美女那是人性，人都喜欢美的东西，这更是人性。";
                    item.eventId = "";
                    item.value = "100个核桃";

                    items.add(item);
                }//End of mock
                break;
            case WalnutNotifyHandler.LOAD_OLD_ACHIEVE_DATA:
                for (int i = 0; i < 2; i++) {
                    item = new WalnutMainEvent();
                    item.AD = "http://skepticfreethought.com/scrapbookoftruth/wp-content/uploads/sites/18/2015/02/Beauty2.jpg";
                    item.title = "淘宝架构的演化过程";
                    item.action = "分享";
                    item.available = "本月可预约5次";
                    item.publisher = "苏妲己";
                    item.role = "高级架构师";
                    item.detail = "一个粗糙的产品，无法用户看上第一眼看上，那就是失败的。男人喜欢看美女那是人性，人都喜欢美的东西，这更是人性。";
                    item.eventId = "";
                    item.value = "100个核桃";

                    items.add(item);
                }//End of mock
                break;
            case WalnutNotifyHandler.INIT_ACHIEVE_DATA:
                for (int i = 0; i < 2; i++) {
                    item = new WalnutMainEvent();
                    item.AD = "http://upload.jashnname.com/UploadedFiles/Core/Images/8ae6b53a-2f23-4a61-81cd-c8d6e6058c92.jpg";
                    item.title = "淘宝架构的演化过程";
                    item.action = "分享";
                    item.available = "本月可预约5次";
                    item.publisher = "苏妲己";
                    item.role = "高级架构师";
                    item.detail = "一个粗糙的产品，无法用户看上第一眼看上，那就是失败的。男人喜欢看美女那是人性，人都喜欢美的东西，这更是人性。";
                    item.eventId = "";
                    item.value = "100个核桃";

                    items.add(item);
                }//End of mock

//                WalnutMainServiceRestfulService restfulService = restAdapter.create(WalnutMainServiceRestfulService.class);
//                restfulService.getAllMainServices(new Callback<MainServiceRestfulWrapper>() {
//                    @Override
//                    public void success(MainServiceRestfulWrapper mainServiceRestfulWrapper, Response response) {
//                        List<MainService> list = mainServiceRestfulWrapper.getList();
//                        List<WalnutMainEvent> items = new ArrayList<>(0);
//                        WalnutMainEvent item;
//                        Transformer mainServiceTransformer = new Transformer
//                                .Builder()
//                                .build(MainService.class);
//                        for(int i=0;null != list && i<list.size();i++){
//                            MainService main = list.get(i);
//                            item = mainServiceTransformer.transform(main, WalnutMainEvent.class);
//                            item.AD = "http://upload.jashnname.com/UploadedFiles/Core/Images/8ae6b53a-2f23-4a61-81cd-c8d6e6058c92.jpg";
//                            item.action = "分享";
//                            item.available = "本月可预约5次";
//                            item.publisher = "苏妲己";
//                            item.role = "高级架构师";
//                            item.value = "100个核桃";
//
//                            items.add(item);
//
//                        }
//                        RetrofitNetworkService.handleSuccess(handler, handlerTag, items.toArray());
//                    }
//
//                    @Override
//                    public void failure(RetrofitError retrofitError) {
//                        RetrofitNetworkService.handleError(handler, handlerTag, null);
//                    }
//                });
                break;
            default:
                break;
        }
        RetrofitNetworkService.handleSuccess(handler, handlerTag, items.toArray());
    }

    public void retrieveHeroDetail(RestAdapter restAdapter, String heroId, final Handler handler, final Integer handlerTag) {
        HeroInfo info = new HeroInfo();
        info.brief = "Hi, 各位好，我是苏妲己。来自华为2012实验室的UCD中心，专门给各种产品提供专业的设计服务";
        info.brief = info.brief + " " + info.brief;
        info.brief = info.brief + " " + info.brief;
        info.skills = new ArrayList<>(4);
        info.skills.add("UI设计");
        info.skills.add("产品设计");
        info.skills.add("漫画");
        info.skills.add("手绘");

        info.headPortrait = "http://skepticfreethought.com/scrapbookoftruth/wp-content/uploads/sites/18/2015/02/Beauty2.jpg";
        RetrofitNetworkService.handleSuccess(handler, handlerTag, info);
    }

    public void retrieveEventDetail(RestAdapter restAdapter, String itemId, String loggedIn,
                                    final Handler handler, final Integer handlerTag) {
        WalnutMainEvent item;
        item = new WalnutMainEvent();
        item.AD = "http://upload.jashnname.com/UploadedFiles/Core/Images/8ae6b53a-2f23-4a61-81cd-c8d6e6058c92.jpg";
        item.title = "淘宝架构的演化过程";
        item.action = "分享";
        item.available = "本月可预约5次";
        item.publisher = "苏妲己";
        item.role = "高级架构师";
        item.detail = "一个粗糙的产品，无法用户看上第一眼看上，那就是失败的。男人喜欢看美女那是人性，人都喜欢美的东西，这更是人性。";
        item.eventId = "";
        item.value = "100个核桃";
        item.status = "已约";
        item.lastUpdate = "";
    }

    public void retrieveEventDetail(RestAdapter restAdapter, String itemId,
                                    final Handler handler, final Integer handlerTag) {
        WalnutMainEvent item;
        item = new WalnutMainEvent();
        item.AD = "http://upload.jashnname.com/UploadedFiles/Core/Images/8ae6b53a-2f23-4a61-81cd-c8d6e6058c92.jpg";
        item.title = "淘宝架构的演化过程";
        item.action = "分享";
        item.available = "本月可预约5次";
        item.publisher = "苏妲己";
        item.role = "高级架构师";
        item.detail = "一个粗糙的产品，无法用户看上第一眼看上，那就是失败的。男人喜欢看美女那是人性，人都喜欢美的东西，这更是人性。";
        item.eventId = "";
        item.value = "100个核桃";
        item.status = "已约";
        item.lastUpdate = "";
    }
}
